#include "stdafx.h"
#include "GameLoop.h"
#include "VoidScene.h"
#include "TestScene.h"

bool GameLoop::Init()
{
	Random::Seed(1);

	EngineDesc desc;	
	desc.Width = m_config.Width;
	desc.Height = m_config.Height;
	desc.Title = m_config.TitleGame;
	desc.Resize = true;

	if ( !m_engine.Init(desc) )
		return false;

	m_module = new ModuleMgr;

	VoidScene *voidscene = new VoidScene;
	m_module->AddModule(VoidSceneName, voidscene);
	TestScene *testscene = new TestScene;
	m_module->AddModule(TestSceneName, testscene);

	m_module->SetActiveModule(VoidSceneName);
		
	return true;
}

void GameLoop::Run()
{
	while ( m_engine.BeginFrame() )
	{
		GameConfig::Get().Resize();

		if (!m_module->Frame())
			break;



		m_engine.EndFrame();
	}
}

void GameLoop::Destroy()
{	
	delete m_module;
	m_engine.Destroy();
}